package stationGUI;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

public class ColorScreen extends JPanel {
  /**
   * 
   */
  private static final long serialVersionUID = 1L;

  ColorSquare currentColor=new ColorSquare(150,100,100,100,Color.RED);
  
  ColorSquare Color1=new ColorSquare(100,300,Color.BLUE);
  ColorSquare Color2=new ColorSquare(200,300,Color.GREEN);
  ColorSquare Color3=new ColorSquare(300,300,Color.RED);
  
  Vector<ColorSquare> change = new Vector<ColorSquare>();;
  
  
  
  ColorScreen() {
    setBorder(BorderFactory.createCompoundBorder(BorderFactory.
        createTitledBorder(BorderFactory.createLineBorder(Color.BLACK,1),
        "Select A Color:"),BorderFactory.createEmptyBorder(0,5,5,5)));
    
    change.add(Color1); 
    change.add(Color2); 
    change.add(Color3); 
    
   /* addMouseListener(new MouseAdapter(){
      public void mousePressed(MouseEvent e){
        currentColor.color=Color.BLUE;  
        repaint();
      }
  });*/
    

  }

  public void addML(int x,int y,int w,int h,Color c){
  addMouseListener(new MouseAdapter(){
    public void mousePressed(MouseEvent e){
      int xPos=e.getX();
      int yPos=e.getY();
      for(ColorSquare current:change) {
        int x=current.getX();
        int y=current.getY();
        if(xPos>x && xPos<x+current.getWidth() && yPos>y && yPos<y+current.getHeight())
          currentColor.color=current.color;;
          repaint();;
      }

    }
    
  });}

  public void paintComponent(Graphics g) {
    super.paintComponent(g);       
    g.drawString("Current Color:",50,100);
    g.drawString("Select Color:",50,280);

    currentColor.paintSquare(g);
    Color1.paintSquare(g);
    Color2.paintSquare(g);
    Color3.paintSquare(g);
    
  }
  public class ColorSquare {
    public int xPos = 50;
    private int yPos = 50;
    private int width = 20;
    private int height = 20;
    public Color color = Color.RED;

    public ColorSquare(int x,int y,int w,int h,Color c) {
      xPos = x;
      yPos = y;
      width = w;
      height = h;
      color = c;
      
      addML(200,y,w,h,Color.BLUE);
    }
      
        
    public ColorSquare(int x,int y,Color c) {
      this(x,y,30,30,c);
    }
    
    
    public void setX(int xPos){ 
      this.xPos = xPos;
    }

    public int getX(){
      return xPos;
    }

    public void setY(int yPos){
      this.yPos = yPos;
    }

    public int getY(){
      return yPos;
    }

    public int getWidth(){
      return width;
    } 

    public int getHeight(){
      return height;
    }

    public void paintSquare(Graphics g){
      g.setColor(color);
      g.fillRect(xPos,yPos,width,height);
      g.setColor(Color.BLACK);
      g.drawRect(xPos,yPos,width,height);  
    }
  }
}
